package com.platform.usercenter.controller;


import cn.hutool.core.collection.CollectionUtil;
import com.platform.common.core.enums.MenuEndPointEnum;
import com.platform.common.core.web.controller.BaseController;
import com.platform.common.core.web.domain.AjaxResult;
import com.platform.usercenter.domain.SysMenuTreeDTO;
import com.platform.usercenter.domain.SysMiniProgramMenu;
import com.platform.usercenter.domain.vo.RouterVo;
import com.platform.usercenter.service.ISysMenuService;
import com.platform.usercenter.service.ISysMiniProgramMenuService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description: 小程序首页菜单信息
 * @Author: wcs
 * @Date: 2024-11-15 11:29:03
 **/
@RestController
@RequestMapping("/sysMiniProgramMenu")
public class SysMiniProgramMenuController extends BaseController {
    @Resource
    ISysMiniProgramMenuService sysMiniProgramMenuService;

    @Resource
    private ISysMenuService menuService;

    @PostMapping("/sava")
    public AjaxResult saveMiniProgramMenuConfig(@RequestBody List<SysMiniProgramMenu> sysMiniProgramMenus) {
        return sysMiniProgramMenuService.saveSysMiniProgramMenu(sysMiniProgramMenus);
    }

    /**
     * 用户配置好的小程序卡片list
     */
    @GetMapping("/useMenuList")
    public AjaxResult userMiniProgramMenuList() {
        List<SysMenuTreeDTO> userMiniProgramMenuList = sysMiniProgramMenuService.getUserMiniProgramMenuList();
        if(CollectionUtil.isNotEmpty(userMiniProgramMenuList)){
            List<RouterVo> routerVos=menuService.buildMenusWeiXin(userMiniProgramMenuList, MenuEndPointEnum.WX_XCX.name(), null);
            return AjaxResult.success(routerVos);
        }
            return AjaxResult.success();
    }
}
